<?php
namespace app\common\model\user;

use think\Db;
use think\Model;

class Send extends Model
{
	// 设置当前模型使用的完整数据库连接信息
	protected $connection = 'database.db_second';//连接配置
	// 表名
	protected $name = 'user_send';
	
	// 自动写入时间戳字段
	protected $autoWriteTimestamp = false;
	
	// 定义时间戳字段名
	protected $createTime = false;
	protected $updateTime = false;
	protected $deleteTime = false;
	
	// 追加属性
	protected $append = [
		'nickname',
		'type_text',
		'news_state_text',
		'is_see_text',
		'create_time_text',
	];
	
	public function getTypeList()
	{
		
		return ['1' => __('点赞'), '2' => __('评论'), '3' => __('留言'), '4' => __('举报'), '5' => __('系统消息')];
	}
	
	public function getNewsStateList()
	{
		
		return ['1' => __('公告驳回'), '2' => __('吧主申请驳回'), '3' => __('管理员申请驳回'), '4' => __('圈子申请驳回')];
	}
	
	public function getIsSeeList()
	{
		
		return ['1' => __('已查看'), '2' => __('未查看')];
	}
	
	public function getTypeTextAttr($value, $data)
	{
		
		$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
		$list  = $this->getTypeList();
		
		return isset($list[$value]) ? $list[$value] : '';
	}
	
	public function getNewsStateTextAttr($value, $data)
	{
		
		$value = $value ? $value : (isset($data['news_state']) ? $data['news_state'] : '');
		$list  = $this->getNewsStateList();
		
		return isset($list[$value]) ? $list[$value] : '';
	}
	
	public function getIsSeeTextAttr($value, $data)
	{
		
		$value = $value ? $value : (isset($data['is_see']) ? $data['is_see'] : '');
		$list  = $this->getIsSeeList();
		
		return isset($list[$value]) ? $list[$value] : '';
	}
	
	public function getCreateTimeTextAttr($value, $data)
	{
		
		$value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
		
		return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
	}
	
	protected function setCreateTimeAttr($value)
	{
		
		return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
	}
	
	public function getNickNameAttr($value, $data)
	{
		
		$nickname = Db::name('user')->where(['id' => $data['user_id']])->value('nickname');
		
		return $nickname ? $nickname : '';
	}
	
}
